﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Add</title>
    <link href="~/Content/layui/css/layui.css" rel="stylesheet" />
</head>
<body>
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">商品名称</label>
            <div class="layui-input-block">
                <input type="text" name="ProductName" id="ProductName" required lay-verify="required" placeholder="请输入商品名称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">商品图片</label>
            <div class="layui-input-block">
                <input id="uploadImg" type="file" name="file">
                <input id="ProductImg" name="ProductImg" type="hidden" />
                <img id="imgPhoto" class="layui-upload-img" style="width:180px; height:140px; border:1px solid" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">商品价格</label>
            <div class="layui-input-block">
                <input type="text" name="Price" id="Price" required lay-verify="required" placeholder="请输入商品价格" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">商品数量</label>
            <div class="layui-input-block">
                <input type="text" name="Count" id="Count" required lay-verify="required" placeholder="请输入商品数量" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">商品简介</label>
            <div class="layui-input-block">
                <input type="text" name="Particulars" id="Particulars" required lay-verify="required" placeholder="请输入商品简介" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">商品地址</label>
            <div class="layui-input-block">
                <input type="text" name="Site" id="Site" required lay-verify="required" placeholder="请输入商品地址" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">上架时间</label>
            <div class="layui-input-block">
                <input type="text" name="CreateTime" id="CreateTime" required lay-verify="required" placeholder="请输入专辑" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="hidden" name="TypeId" id="TypeId" value="1" required lay-verify="required" placeholder="请输入专辑" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">上架/下架</label>
            <div class="layui-input-block">
                <select name="Isstate" id="Isstate" lay-verify="required">
                    <option value="">请选择</option>
                    <option value="上架">上架</option>
                    <option value="下架">下架</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
    <script src="~/Content/layui/layui.js"></script>
    <script src="~/Content/js/jquery-1.8.2.min.js"></script>
    <script>
        //Demo
        layui.use('form', function () {
            var form = layui.form;
            var $ = layui.$;
            var layer = layui.layer;
            var laydate = layui.laydate;
            var upload = layui.upload;
            //开始日期范围
            laydate.render({
                elem: '#CreateTime'
            });
            //监听提交
            form.on('submit(formDemo)', function (data) {

                $.post("/Prdouct/Add", {
                    ProductName: $("#ProductName").val(),
                    ProductImg: $("#ProductImg").val(),
                    Price: $("#Price").val(),
                    Count: $("#Count").val(),
                    Particulars: $("#Particulars").val(),
                    Site: $("#Site").val(),
                    CreateTime: $("#CreateTime").val(),
                    TypeId: $("#TypeId").val(),
                    Isstate: $("#Isstate").val()

                }, function (res) {
                    if (res.Success) {
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                        window.parent.location.reload();
                        layer.msg(res.Message)
                    } else {
                        layer.msg(res.Message)
                    }

                })
                return false;
            });

            upload.render({
                elem: '#uploadImg'
                , url: '/TuPianShangChuan/UploadPhoto'
                , method: "post"
                , done: function (res) {

                    if (res.success) {
                        $("#ProductImg").val(res.remark);
                        $("#imgPhoto").attr("src", "/Content/" + res.remark);
                    } else {
                        layer.msg("上传失败:" + res.message);
                    }
                }
                , error: function () {

                }
            });



        });
    </script>
</body>
</html>
